<template>
	<view class="page">
		<image src="../../static/register/top.jpg" mode="widthFix" class="top" />
		<view class="location-container">
			<view class="left">
				<image src="../../static/register/location.png" mode="widthFix" class="location"></image>
				<text>代驾服务地点</text>
			</view>
			<view class="right">重庆市渝北区</view>
		</view>
		<view class="info-container">
			<view class="title-container">
				<image src="../../static/register/title-bg.png" mode="widthFix" class="title-bg"></image>
				<text class="title">基本要求</text>
			</view>
			<view class="list">
				<view class="item">
					<text>1.</text>
					三年安全驾驶经验；
				</view>
				<view class="item">
					<text>2.</text>
					年龄23~55周岁；
				</view>
				<view class="item">
					<text>3.</text>
					无违法犯罪记录、无精神病史、无吸毒史，以及平台认为不适合代驾的其他历史证明；
				</view>
				<view class="item">
					<text>4.</text>
					有熟练驾车经验；
				</view>
				<view class="item">
					<text>5.</text>
					身体健康，无肢体残疾和大面积纹身；
				</view>
				<view class="item">
					<text>6.</text>
					需要提供身份证、驾驶证、直系亲属联系方式，并保存前述材料的真实合法性；
				</view>
			</view>
		</view>
		<view class="info-container">
			<view class="title-container">
				<image src="../../static/register/title-bg.png" mode="widthFix" class="title-bg"></image>
				<text class="title">基本要求</text>
			</view>
			<view class="list">
				<view class="complex-item">
					<view class="left">01</view>
					<view class="right">
						<text class="item-title">在线注册</text>
						<text class="item-desc">在小程序上完成注册</text>
					</view>
				</view>
				<view class="complex-item">
					<view class="left">02</view>
					<view class="right">
						<text class="item-title">基本信息提交</text>
						<text class="item-desc">按照流程提交本人身份证、驾驶证</text>
					</view>
				</view>
				<view class="complex-item">
					<view class="left">03</view>
					<view class="right">
						<text class="item-title">信息审核</text>
						<text class="item-desc">对提交信息以及证件进行审核</text>
					</view>
				</view>
				<view class="complex-item">
					<view class="left">04</view>
					<view class="right">
						<text class="item-title">签署合同</text>
						<text class="item-desc">收到邮寄的合同后必须本人签署</text>
					</view>
				</view>
			</view>
		</view>
		<button class="btn" open-type="getUserInfo" @tap="register()">立即注册</button>
		<u-toast ref="uToast" />
	</view>
</template>

<script>
export default {
	data() {
		return {
			code: null
		};
	},
	methods: {
		register(){
			const that =this
			
			//获取令牌
			const token=uni.getStorageSync("token")
			if(token){
				//根据令牌获取当前司机的信息，进行下一步判断
				this.authRealCheck()				
			}else{
				that.applyNewDriver()
			}			 
		},
		//注册检查
    authRealCheck(){
      const that=this
      that.ajax(that.url.registerRealAuth,"get",null,(resp)=> {
        const result=resp.data
        if(result===1){
          uni.redirectTo({
            url: '../../identity/filling/filling?mode=create'  //进入实名认真的界面
          });
        }else if(result===2){
          that.jump('资料正在审核中，请稍后','../login/login')
        }else if(result===3){
          //人脸识别
          uni.redirectTo({
            url: "../../identity/face_camera/face_camera?mode=create" //进入人脸识别的界面
          });
        }else{
          //让用户自己重新点击一下审核
          that.applyNewDriver()
        }

      });
    },
		// 重新申请司机注册
		applyNewDriver(){
			//申请小程序临时授权码
			const that=this
			uni.login({
				success(resp) {
					that.code = resp.code
				}
			})
			
			//获取小程序用户信息
			uni.getUserInfo({
				success(resp) { 
					const userInfo={}
					userInfo.nickname= resp.userInfo.nickName
					userInfo.photo= resp.userInfo.avatarUrl
					userInfo.gender = resp.userInfo.gender 
					userInfo.code = that.code
					
					//向后台发送ajax请求
					that.ajax(that.url.registerNewDriver,"POST",userInfo,(resp)=> {
						console.log(resp)
						//注册，跳转到 司机身份认证页面，realAuth=1存储到  uniapp存储容器中
						uni.setStorageSync('realAuth', 1);
						let token = resp.data.token; //必须这么写
						uni.setStorageSync('token', token);
						// 小程序的show toast 是异步的。不能使用
						that.jump('注册成功,进行实名认证','../../identity/filling/filling?mode=create')			
					 
					})
				}
			})
		},
		jump(title,url){
		 this.$refs.uToast.show({
		 	title: title,
		 	type: 'success',
		 	callback: function() { //显示完成后，执行
		 		uni.redirectTo({
		 			url: url  //进入实名认真的界面
		 		});
		 	}
		 });			
		}
	}
};
</script>

<style lang="less">
@import url('register.less');
</style>
